#ifndef T1_DEFENDER_H_
#define T1_DEFENDER_H_

#include "iodef.h"

typedef struct {
        __IO uint32_t NVSRAM_CTL;
        __IO uint32_t Reserved1[3];
        __IO uint32_t DEF_CTL;
        __IO uint32_t INT_STA;
        __IO uint32_t INT_EN;
        __IO uint32_t INT_CLR;
        __IO uint32_t CUR_STA;
        __IO uint32_t Reserved2[3];
        __IO uint32_t ATP_SEL;
        __IO uint32_t TEMP_CFG;
        __IO uint32_t ROSC_PD;
        __IO uint32_t Reserved3;
        __IO uint32_t T1_TIME;
        __IO uint32_t T2_TIME;
        __IO uint32_t IN_MESH_T345;
        __IO uint32_t EX_MESH_T345;
        __IO uint32_t SW_T345;
        __IO uint32_t TEMP_TIME;
        __IO uint32_t RVDT_TIME;
        __IO uint32_t DEBOUNCE_N;
        __IO uint32_t LOCK_TIME;
        __IO uint32_t CLK32K_CTL;
        __IO uint32_t NVSRAM_CLR;
        __IO uint32_t TEST_SAFE;
        __IO uint32_t LOCK_EN;
        __IO uint32_t ERR33_CLR;
}def_reg_t;

/* NVSRAM_CTL */
#define NVSRAM_BANK0_WR_EN              _BIT(5)
#define NVSRAM_BANK0_RD_EN              _BIT(4)
#define NVSRAM_CLK_SEL_32K              _BIT(1)
#define NVSRAM_RW_EN                    _BIT(0)

/* DEF_CTL */
#define INT_3P3V_UPT                    _BIT(16)
#define RESET_EN                        _BIT(15)
#define IO_VOLD_EN                      _BIT(14)
#define CORE_VOLD_EN                    _BIT(13)
#define MOSCD_EN                        _BIT(12)
#define DEBOUNCE_EN                     _BIT(11)
#define RTC_FRQD_EN                     _BIT(10)
#define VDT_FILTERD_EN                  _BIT(9)
#define RTC_VOLD_EN                     _BIT(8)
#define NVSRAM_CLR_EN                   _BIT(7)
#define TEMPD_EN                        _BIT(6)
#define ATP_CUR_MODE                    _BIT(5)
#define ATP_EN                          _BIT(4)
#define DEF_INT_EN                      _BIT(1)
#define DEF_EN                          _BIT(0)

/* INT_STA, INT_EN, INT_CLR */
#define DEF_TRIG_ERR                    _BIT(31)
#define DEF_NVSRAM_CLR_DONE             _BIT(30)
#define DEF_RTC_CLK_HIGH                _BIT(29)
#define DEF_RTC_CLK_LOW                 _BIT(28)
#define DEF_RTC_VOL_HIGH                _BIT(27)
#define DEF_RTC_VOL_LOW                 _BIT(26)
#define DEF_TEMP_HIGH                   _BIT(25)
#define DEF_TEMP_LOW                    _BIT(24)
#define DEF_V_IN_N                      _BIT(23)
#define DEF_V_IN_P                      _BIT(22)
#define DEF_V_EX_N                      _BIT(21)
#define DEF_V_EX_P                      _BIT(20)
#define DEF_V_SW                        _MASK(16, 4)
#define DEF_I_SW_ID                     _MASK(12, 4)
#define DEF_I_SW_IS                     _MASK(8, 4)
#define DEF_I_EX_ID                     _MASK(6, 2)
#define DEF_I_EX_IS                     _MASK(4, 2)
#define DEF_CLK_MOSC_ERR                _BIT(2)
#define DEF_IO_VOL_HIGH                 _BIT(1)
#define DEF_CORE_VOL_HIGH               _BIT(0)

#define DEF_STATUS_MASK                 0xFFFFFFF7

/* LOCK_EN */
#define PARA_LOCK                       _BIT(3)
#define ANA_LOCK                        _BIT(2)
#define DEF_LOCK                        _BIT(1)
#define NVSRAM_LOCK                     _BIT(0)
#define LOCK_MASK                       _MASK(0,4)

/* ATP_SEL */
#define DEF_ATP_SEL_MASK                _MASK(0, 20)
#define DEF_ATP_SW4_EN			_BIT(4)
#define DEF_ATP_SW5_EN			_BIT(5)

#define DEF_ATP_VOL_ALL			0xFFF000
#define DEF_ATP_CUR_ALL			0xFFF
#define DEF_ATP_CUR_ALL_P1		0x77F

#define DEF_ATP_VOL_SW0_EN			_BIT(12)
#define DEF_ATP_VOL_SW1_EN			_BIT(13)
#define DEF_ATP_VOL_SW2_EN			_BIT(14)
#define DEF_ATP_VOL_SW3_EN			_BIT(15)

/* TEMP_CFG */
#define DEF_TEMP_OVER_CFG_MASK          _MASK(4, 2)
#define DEF_TEMP_OVER_85                _VALUE(4, 0x1)
#define DEF_TEMP_OVER_95                _VALUE(4, 0x2)
#define DEF_TEMP_OVER_105               _VALUE(4, 0x3)

#define DEF_TEMP_UNDER_CFG_MASK         _MASK(0, 2)
#define DEF_TEMP_UNDER_15               _VALUE(0, 0x1)
#define DEF_TEMP_UNDER_25               _VALUE(0, 0x2)
#define DEF_TEMP_UNDER_35               _VALUE(0, 0x3)

/* T1_TIME */
#define DEF_T1_TIME_MASK                _MASK(0, 4)
#define DEF_T1_TIME_2MS                 _VALUE(0, 0)
#define DEF_T1_TIME_4MS                 _VALUE(0, 1)
#define DEF_T1_TIME_8MS                 _VALUE(0, 2)
#define DEF_T1_TIME_16MS                _VALUE(0, 3)
#define DEF_T1_TIME_32MS                _VALUE(0, 4)
#define DEF_T1_TIME_64MS                _VALUE(0, 5)
#define DEF_T1_TIME_128MS               _VALUE(0, 6)
#define DEF_T1_TIME_256MS               _VALUE(0, 7)
#define DEF_T1_TIME_512MS               _VALUE(0, 8)
#define DEF_T1_TIME_1S                  _VALUE(0, 9)

/* T2_TIME */
#define DEF_T2_TIME_MASK                _MASK(0, 3)
#define DEF_T2_TIME_31_25US             _VALUE(0, 0)
#define DEF_T2_TIME_62_5US              _VALUE(0, 1)
#define DEF_T2_TIME_125US               _VALUE(0, 2)
#define DEF_T2_TIME_250US               _VALUE(0, 3)
#define DEF_T2_TIME_500US               _VALUE(0, 4)
#define DEF_T2_TIME_1MS                 _VALUE(0, 5)
#define DEF_T2_TIME_2MS                 _VALUE(0, 6)
#define DEF_T2_TIME_4MS                 _VALUE(0, 7)

/* IN_MESH_T345, EX_MESH_T345, SW_T345 */
#define DEF_T5_MASK                     _MASK(8, 3)
#define DEF_T5_125US                    _VALUE(8, 0)
#define DEF_T5_250US                    _VALUE(8, 1)
#define DEF_T5_500US                    _VALUE(8, 2)
#define DEF_T5_1MS                      _VALUE(8, 3)
#define DEF_T5_2MS                      _VALUE(8, 4)
#define DEF_T5_4MS                      _VALUE(8, 5)
#define DEF_T5_8MS                      _VALUE(8, 6)
#define DEF_T5_16MS                     _VALUE(8, 7)

#define DEF_T4_MASK                     _MASK(4, 3)
#define DEF_T4_125US                    _VALUE(4, 0)
#define DEF_T4_250US                    _VALUE(4, 1)
#define DEF_T4_500US                    _VALUE(4, 2)
#define DEF_T4_1MS                      _VALUE(4, 3)
#define DEF_T4_2MS                      _VALUE(4, 4)
#define DEF_T4_4MS                      _VALUE(4, 5)
#define DEF_T4_8MS                      _VALUE(4, 6)
#define DEF_T4_16MS                     _VALUE(4, 7)

#define DEF_T3_MASK                     _MASK(0, 3)
#define DEF_T3_62_5US                   _VALUE(0, 0)
#define DEF_T3_125US                    _VALUE(0, 1)
#define DEF_T3_250US                    _VALUE(0, 2)
#define DEF_T3_500US                    _VALUE(0, 3)
#define DEF_T3_1MS                      _VALUE(0, 4)
#define DEF_T3_2MS                      _VALUE(0, 5)
#define DEF_T3_4MS                      _VALUE(0, 6)
#define DEF_T3_8MS                      _VALUE(0, 7)

/* TEMP_TIME */
#define DEF_TEMP_TIME_MASK              _MASK(0, 3)
#define DEF_TEMP_TIME_250US             _VALUE(0, 0)
#define DEF_TEMP_TIME_312_5US           _VALUE(0, 1)
#define DEF_TEMP_TIME_375US             _VALUE(0, 2)
#define DEF_TEMP_TIME_437_5US           _VALUE(0, 3)
#define DEF_TEMP_TIME_500US             _VALUE(0, 4)
#define DEF_TEMP_TIME_562_5US           _VALUE(0, 5)
#define DEF_TEMP_TIME_625US             _VALUE(0, 6)
#define DEF_TEMP_TIME_687_5US           _VALUE(0, 7)

/* RVDT_TIME */
#define DEF_RVDT_TIME_WIDTH_MASK        _MASK(4, 3)
#define DEF_RVDT_TIME_WIDTH_125US       _VALUE(4, 0)
#define DEF_RVDT_TIME_WIDTH_156_25US    _VALUE(4, 1)
#define DEF_RVDT_TIME_WIDTH_187_5US     _VALUE(4, 2)
#define DEF_RVDT_TIME_WIDTH_218_75US    _VALUE(4, 3)
#define DEF_RVDT_TIME_WIDTH_250US       _VALUE(4, 4)
#define DEF_RVDT_TIME_WIDTH_281_25US    _VALUE(4, 5)
#define DEF_RVDT_TIME_WIDTH_312_5US     _VALUE(4, 6)
#define DEF_RVDT_TIME_WIDTH_343_75US    _VALUE(4, 7)

#define DEF_RVDT_TIME_INTV_MASK         _MASK(0, 3)
#define DEF_RVDT_TIME_INTV_16MS         _VALUE(0, 0)
#define DEF_RVDT_TIME_INTV_32MS         _VALUE(0, 1)
#define DEF_RVDT_TIME_INTV_64MS         _VALUE(0, 2)
#define DEF_RVDT_TIME_INTV_128MS        _VALUE(0, 3)
#define DEF_RVDT_TIME_INTV_256MS        _VALUE(0, 4)
#define DEF_RVDT_TIME_INTV_512MS        _VALUE(0, 5)
#define DEF_RVDT_TIME_INTV_1S           _VALUE(0, 6)

/* LOCK_TIME */
#define DEF_LOCK_TIME_MASK              _MASK(0, 2)
#define DEF_LOCK_TIME_125MS             _VALUE(0, 0)
#define DEF_LOCK_TIME_250MS             _VALUE(0, 1)
#define DEF_LOCK_TIME_375MS             _VALUE(0, 2)
#define DEF_LOCK_TIME_500MS             _VALUE(0, 3)

#define DEF     ((def_reg_t *)T1_DEF_BASE)

#endif /* T1_DEFENDER_H_ */
